using NUnit.Framework;

namespace TDUnit.Examples
{
    [TestFixture]
    public class SqlServerTestDataTests : SqlServerTestDataTestsBase
    {
        protected override string GetTestDataString()
        {
            return
            @"
                <TestData>
                    <Table Name='SimpleTable' PrimaryKey='ID' IsAutoIdentity='True'>
                        <Row Name='SimpleRow' TestColumn='TestValue' />
                    </Table>
                    <Table Name='SimpleTableChild' PrimaryKey='ID' IsAutoIdentity='True'>
                        <Row TestColumn='Test Value' SimpleTableID='$(SimpleTable.SimpleRow.ID)' />
                    </Table>
                </TestData>
            ";
        }

        [Test]
        public void ReadTestData()
        {
            Assert.AreEqual(1, int.Parse(ExecuteScalarQuery("SELECT COUNT(*) FROM SimpleTable").ToString()));
            Assert.AreEqual(1, int.Parse(ExecuteScalarQuery("SELECT COUNT(*) FROM SimpleTableChild").ToString()));

            var simpleTableRowIDInChild = int.Parse(ExecuteScalarQuery("SELECT SimpleTableID FROM SimpleTableChild").ToString());
            var simpleTableRowID = int.Parse(ExecuteScalarQuery("SELECT ID FROM SimpleTable").ToString());
            
            Assert.AreEqual(simpleTableRowID, simpleTableRowIDInChild);
        }
    }
}